<%@include file="/pub/import.jsp"%>
<%@include file="/pub/header.jsp"%>
<%
	String treeOrItem="tree";
	int projectId = RequestUtil.getIntParameter(request,"id",0);
	int treeId = RequestUtil.getIntParameter(request,"treeId",0);
	Project project = ProjectHandler.getProject(projectId);
	String ignoreIds = "";
	
    if(StringUtils.isEmpty(project.getBuildUnit())) ignoreIds += "1,";
    if(StringUtils.isEmpty(project.getConstructUnit())) ignoreIds += "3,";
    if(StringUtils.isEmpty(project.getSupervisorUnit())) ignoreIds += "40,";
    if(StringUtils.isEmpty(project.getDesignUnit())) ignoreIds += "44,";
    
    ScoreTree tree = ScoreTreeHandler.loadById(treeId);//延时加载评分子项,先加载树
    
    
    ignoreIds = StringUtil.cutLastComm(ignoreIds);
    context.put("cateTree", ScoreTreeHandler.getTreeOptionString(ignoreIds));
    context.put("treeId", treeId);
    context.put("projectId", projectId);
    
    if(treeId!=0)
    {
	    String ScoreItemName = "";
	    String projectItem_ScoreItemName="";
	    String allhava="";
	    
	    ScoreTree controlTree = ScoreTreeHandler.getControlTreeByTree(tree.getId());
	    if(controlTree!=null) {
	      context.put("percent", controlTree.getPercent());
	    }else{
	      context.put("percent", 0);
	    }
    
	    //得到当前tree的ScoreItem对像
	    /*
	    Set<ScoreItem> scoreItem = tree.getScoreItems();//得到最终评分子项,最终评分子项关联评分项表中的ProjectItems
	    Map<Integer, ScoreItem>  scorteItemMap = new HashMap<Integer, ScoreItem>();
	    if(scoreItem!=null)
	    {
		    for(ScoreItem list_scoreItem:scoreItem)
		    {
			    if(!scorteItemMap.containsKey(list_scoreItem.getId()))
			    {
			    	scorteItemMap.put(list_scoreItem.getId(),list_scoreItem);
			    	ScoreItemName=ScoreItemName+","+list_scoreItem.getId();
			    }
		    }
	    }
	    
	    
	    //取得项目中的ProjectItems相关的ScoreItem的对像，与tree的ScoreItem对像的做比较用
	    Set<ProjectItems> projectItem_ScoreItem = project.getProjectItemses();
	    Map<Integer, ScoreItem>  projectItemMap_ScoreItem = new HashMap<Integer, ScoreItem>();
	    if(projectItem_ScoreItem!=null)
	    {
	    	for(ProjectItems pi :projectItem_ScoreItem)
	    	{
		    	if(!projectItemMap_ScoreItem.containsKey(pi.getScoreItem().getId()))
		    	{
		    		//projectItemMap.put(pi.getScoreItem().getId(),pi.getScoreItem().getProjectItemses());
		    		projectItemMap_ScoreItem.put(pi.getScoreItem().getId(),pi.getScoreItem());
		    		projectItem_ScoreItemName=projectItem_ScoreItemName+","+pi.getScoreItem().getId();
		    	}
	    	}
	    }
	    
	    
	    Set<ScoreItem> resultProjectItems_ScoreItem= new HashSet<ScoreItem>();//先找到相关联的ScoreItem
	    Iterator it = scorteItemMap.keySet().iterator();
	    while(it.hasNext())
	    {
	    	Integer key = (Integer)it.next();
	    	if(projectItemMap_ScoreItem.containsKey(key))
	    	{
	    		//resultProjectItems.addAll(projectItemMap.get(key));
	    		resultProjectItems_ScoreItem.add(projectItemMap_ScoreItem.get(key));
	    		allhava = allhava+","+key;
	    	}
	    }
	    
	    
	    Set<ProjectItems>  resultProjectItems= new HashSet<ProjectItems>();//再找到当前项目下的ProjectItems
	    Iterator itt = resultProjectItems_ScoreItem.iterator();
	    while(itt.hasNext())
	    {
	       ScoreItem si = (ScoreItem)itt.next();
	       if(projectItemMap.containsKey(si.getId()))
	       {
	       		resultProjectItems.addAll(projectItemMap.get(si.getId()));
	       }
	    }*/
	    
	    
	    List<ProjectItems> resultProjectItems= ProjectItemsHandler.getByProjectIdTreeId(projectId,treeId);
	    
	    if(resultProjectItems!=null && resultProjectItems.size()>0)//如果分项目中是没有此treeID记录
	    {
	   		 float addScoure = 0.0f;
	   		 for(ProjectItems pi : resultProjectItems)
	   		 {
	   		 	addScoure+=pi.getScore();
	   		 }
	   		 treeOrItem="items";
	   		 context.put("projectItemsList",resultProjectItems);
	   		 context.put("addScoure",addScoure);
	    }
	    
	    else//直接显示评分子项
	    {
	    	context.put("itemList", tree.getScoreItems());
	    	context.put("addScoure",0);
	    }
    }
    context.put("scoreTree",tree);
    context.put("treeOrItem",treeOrItem);
	out.println(TemplateUtil.getOutput(context,"/view/project/addNewProject_StepTwoNew.html"));
%>
<%@include file="/pub/footer.jsp"%>